<?php
/**
 * 网春确认发布
 */
//require_once dirname(dirname(__DIR__))."/common.php";
require_once dirname(__DIR__)."/login_filter.php";
use app\cls\tom\Response;
use app\cls\tom\SysResource;
use app\cls\tom\Tools;
use app\cls\tom\Config;
use app\cls\tom\FFmpeg;
use app\model\Activity;
$host_id=$_POST['host_id'];//主持人id
$select_person_id=$_POST['select_person_id'];//拜年对象id
$video_title=$_POST['video_title'];//拜年对象id
if(empty($host_id) || empty($select_person_id) || empty($video_title)){
    Response::output(-1,"缺少参数");
}
//实例化数据库
$db = SysResource::getDB(true);
$Activity=new Activity($db);
$datas=$Activity->wangchun_one(['wangchun_host'=>$host_id,"wangchun_select_person"=>$select_person_id],"id,wangchun_host,wangchun_select_person,wangchun_host_name,wangchun_select_person_name,wangchun_video_url,wangchun_pic,wangchun_big_pic,wangchun_share_pic,wangchun_title,wangchun_duration,wangchun_height,wangchun_width,wangchun_huati,wangchun_fenlei");
if(empty($datas)){
    Response::output(-1,"服务内部有错");
}
//截取第一帧封面
$ffmpeg = new FFmpeg();
$img_path=upload_dir();
$re=$ffmpeg->getCoverFromVideo1($video_url,$img_path['savepath']);

//生成video_uuid
$k1=mt_rand(100000, 999999);
$k2=mt_rand(100000, 999999);
$k3=mt_rand(1000000, 9999999);
$k4=mt_rand(1000, 9999);
$k5=$k1.$k2.$k3.$k4;
//拼接数据如入数据库
$data['material_id']="网春";
$data['uuid']=$Auth['uuid'];
$data['video_uuid']=$k5;
$data['nick_name']=$Auth['nick_name'];
$data['nick_pic']=$Auth['nick_pic'];
$data['pic']=$datas['wangchun_pic'];
$data['share_pic']=$datas['wangchun_share_pic'];
$data['hengping_pic']=$datas['wangchun_big_pic'];
$data['video_desc']=$video_title;
$data['width2']=$datas['wangchun_width'];
$data['height2']=$datas['wangchun_height'];
$data['duration']=$datas['wangchun_duration'];
$data['join_type']=$datas['wangchun_fenlei'];
$data['join_type_sub']=$datas['wangchun_huati'];
$data['video_url']=$datas['wangchun_video_url'];
$data['examine']=3;
$data['type']=2;
$data['is_dub']=1;
$data['is_save']=1;
$data['mix_status']=1;
$data['is_job_status']=2;
$data['is_wangchun']=1;//1为网春（前端上传），2不是网春，3为网春（后台上传）
$data['add_time']=date("Y-m-d H:i:s",time());
$data['first_pic3']=$img_path['savehttp'];
$data['user_score']=1;
//Response::output(0,"发布成功",$data);
//添加入库
$res=$Activity->add_material($data);
if($res){
    Response::output(0,"发布成功");
}else{
    Response::output(-1,"发布失败");
}




function upload_dir($type="image",$suffix="jpg"){
    //解决跨域问题
    $allUploadConfig = Config::load("cos_upload");

    $uploadConfig = $allUploadConfig[$type];

    //创建上传目录，配置上传
    $date1=date("Y",time());
    $date2=date("m",time());
    $date3=date("d",time());
    $dir="/".$date1."/".$date2."/".$date3;
    $uploadpath1=$uploadConfig['savepath'];
    $uploadpath2=$uploadConfig['savehttp'];
    $key1=rand(1000,10000);
    $key2=rand(10000,20000);
    $key3=rand();
    $file_name=$key1.$key2.$key3;
    //这是服务器上的上传地址
    $uploadpath['savepath']=$uploadpath1.$dir."/".$file_name.".{$suffix}";
    if($type!="image"){
        mkdir($uploadpath1.$dir,0777,true);
    }
    //这是网络访问地址
    $uploadpath['savehttp']=$uploadpath2.$dir."/".$file_name.".{$suffix}";
    return $uploadpath;
}
